using UnityEngine;
using System.Collections;

public class Building : MonoBehaviour {
	
	public float speed = 3;
	private SantaClaus player;
    private bool isGood;

	void Start()
	{
        try { player = GameObject.FindGameObjectWithTag("Player").GetComponent<SantaClaus>(); }
        catch { }

        int random =  Random.Range(0, 101);

        if(random >= 50)
        {
            isGood = true;
            //renderer.material.color = Color.green;
        }
        else
        {
            isGood = true;
            //isGood = false;
        }
	}
	
	void Update() 
	{	
		transform.Translate(-speed*Time.deltaTime,0,0);
		
		if(transform.position.x <= -15)
		{
			Destroy(this.gameObject);
		}
	}
	
	void OnTriggerEnter(Collider other)
	{
		if(other.gameObject.tag == "Gift")
		{
            if(isGood)
            {
                PlayerInformations.AddPoints(100);
            }
            else
            {
                PlayerInformations.AddPoints(-50);
            }

			Destroy(other.gameObject);
		}
		
		if(other.gameObject.tag == "Player")
		{
            player.Die();
		}
		
		if(other.gameObject.tag == "Bird")
		{
			Destroy(other.gameObject);
		}
	}
}